<html xmlns="http://www.w3.org/1999/xhtml">
<head>
  <meta charset="utf-8">
  <title><!--{$lang.page.index.title}--></title>
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
  <link rel="stylesheet" href="/static/lay/layui/css/layui.css" media="all">
  <link rel="stylesheet" href="/static/lay/layui/index.css" media="all">
</head>
<body>

<div class="layui-fluid">
    <div class="layui-card">
      <div class="layui-card-body" style="padding: 15px;">
        <form name="addItem" method="post" lay-filter="component-form-group" class="layui-form">
          <input type="hidden" value="<!--{$datainfo.aid}-->" name="aid">
          <input type="hidden" value="<!--{$gift}-->" name="gift">
          <input type="hidden" value="<!--{$userate}-->" name="rates">
          <input type="hidden" name="userate" value="<!--{$userate}-->" >
          <input type="hidden" name="ratebase" value="<!--{$ratebase}-->" >
          <input type="hidden" value="1" name="status">
          <div class="layui-form-item">
            <div class="layui-inline">
              <label class="layui-form-label"><!--{$lang.page.table.cashin}--><!--{$lang.page.table.curtype}--></label>
              <div class="layui-input-inline">
                <select name="currency" lay-filter="brickType" style="padding-right: 0px">
                  <!--{foreach from=$exchange item=item key=key}--> 
                    <option data-rate="<!--{$item.rate}-->" value="<!--{$item.codes}-->" <!--{if $item.codes eq $datainfo.currency}-->selected<!--{/if}-->><!--{$item.name}-->-<!--{$item.rate}--></option>
                  <!--{/foreach}-->
                </select>
              </div>
            </div>

            <div class="layui-inline">
              <label class="layui-form-label"><!--{$lang.page.table.cashin}--><!--{$lang.page.table.money}--></label>
              <div class="layui-input-inline">
                <input type="text" name="money" id="money" value="<!--{$datainfo.money}-->" lay-verify="money" class="layui-input" />
              </div>
            </div>

            <div class="layui-inline showintegra" >
              <label class="layui-form-label"><!--{$lang.page.table.give}--><!--{$lang.page.table.money}--></label>
              <div class="layui-input-inline">
                <input type="text" name="integra" id="integra" value="<!--{$datainfo.integra}-->" class="layui-input" />
              </div>
            </div>

            <div class="layui-inline">
              <label class="layui-form-label"><!--{$lang.page.table.type}--></label>
              <div class="layui-input-block">
                <input type="radio" name="type" value="1" lay-filter="type" title="<!--{$lang.page.table.tradeing}-->" <!--{if $datainfo.type eq 1}--> checked<!--{/if}-->>&nbsp;&nbsp;<input type="radio" name="type" value="2" lay-filter="type" title="<!--{$lang.page.table.virtual}-->" <!--{if $datainfo.type eq 2}--> checked<!--{/if}-->>
              </div>
            </div>

          </div>
          <div class="layui-form-item">
            <div class="layui-inline">
              <label class="layui-form-label"><!--{$lang.page.table.exchange}--><!--{$lang.page.table.curtype}--></label>
              <div class="layui-input-inline">
                <input type="text" name="codes" class="layui-input" value="<!--{$currency}-->" readonly>
              </div>
            </div>

            <div class="layui-inline">
              <label class="layui-form-label"><!--{$lang.page.table.exchange}--><!--{$lang.page.table.money}--></label>
              <div class="layui-input-inline">
                <input type="text" name="remoney" id="remoney" value="<!--{$datainfo.remoney}-->" lay-verify="money" class="layui-input" readonly/>
              </div>
            </div>

            <div class="layui-inline showintegra">
              <label class="layui-form-label"><!--{$lang.page.table.give}--><!--{$lang.page.table.exchange}--></label>
              <div class="layui-input-inline">
                <input type="text" name="reintegra" id="reintegra" value="<!--{$datainfo.reintegra}-->" class="layui-input" readonly/>
              </div>
            </div>

            <div class="layui-inline">
              <label class="layui-form-label"><!--{$lang.page.table.exchange}--><!--{$lang.page.table.rate}--></label>
              <div class="layui-input-inline">
                <input type="text" name="rate" class="layui-input layui-btn-disabled" value="<!--{$datainfo.rate}-->" readonly>
              </div>
            </div>

          </div>

          <div class="layui-form-item">
              <label class="layui-form-label"><!--{$lang.page.table.receipt}--></label>
              <div class="layui-inline">
                <div>
                  <blockquote class="viewpicList">
                  <ul><li class="viewpic" id="picdemo" <!--{if empty($datainfo.file_url)}-->style="display:none;"<!--{/if}-->>
                      <img id="demo" src="<!--{$datainfo.file_url}-->" onclick="xadmin.showimg({url:'<!--{$datainfo.file_url}-->'});"/></li>
                      <button type="button" class="picup" id="upload" <!--{if !empty($datainfo.file_url)}-->style="display:none;"<!--{/if}-->>+</button>
                  </ul>
                  </blockquote>
                </div>
                <input id="file_url" name="file_url" value="<!--{$datainfo.file_url}-->" type="hidden" lay-verify="file_url" />
              </div>
          </div>
          <div class="layui-form-item layui-layout-admin">
            <div>
              <div class="layui-footer" style="left: 0; margin-bottom:0 ">
                <!--{if $datainfo.status <3 }--> 
                <button class="layui-btn" type="button" id="submit" lay-submit lay-filter="submit"><!--{$lang.page.public.submit}--></button>
                <!--{/if}--> 
                <button type="reset" class="layui-btn layui-btn-primary"><!--{$lang.page.public.reset}--></button>
                <button type="button" class="layui-btn layui-btn-primary" onClick="xadmin.close();" ><!--{$lang.page.table.back}--></button>
              </div>
            </div>
          </div>
        </form>
      </div>
    </div>
  </div>
<script src="/static/lay/layui/layui.js"></script>
  <script type="text/javascript">
    layui.config({
     base: '/static/lay/' //静态资源所在路径
   }).extend({
     xadmin: 'lib/xadmin' //弹窗
   }).use(['jquery', 'layer','xadmin', 'form','upload'], function(){
    var form = layui.form;
    var upload = layui.upload;
    form.render(null, 'component-form-group');
    moneyinput=/\d+/;
    /* 自定义验证规则 */
    form.verify({
      money: function(value){
        if(value <= 0){
          return '<!--{$lang.page.public.paraerror}-->';
        }
        if(!moneyinput.test(value)){
          return '<!--{$lang.page.public.paraerror}-->';
        }
      }
    });
    let ratebase = $('input[name="ratebase"]').val();
    let rate = $('input[name="rate"]').val();
    let gift = $('input[name="gift"]').val();
    $(function(){
        $('#money').on('input',function(e){
            money=e.delegateTarget.value;
            let rates = $('input[name="rates"]').val();
            rate = $('input[name="rate"]').val();
            $("#integra").val(money*gift/100);
            $('input[name="remoney"]').val((money*rate).toFixed(2));
            $('input[name="reintegra"]').val(((money*gift/100)*rate).toFixed(2));
        })
    })

    form.on('radio(type)', function(data) {
        var value = data.value; // 获取被选中的值
        if(value==1){
          $('.showintegra').show();
        }else{
          $('.showintegra').hide();
        }   
    });

    form.on('select(brickType)', function(data) {
        let rates = $(data.elem).find("option:selected").attr("data-rate");
        $('input[name="rates"]').val(rates);
        let userate = $('input[name="userate"]').val();
        let money = $('input[name="money"]').val();
        let rate = (ratebase/rates)*userate;
        $('input[name="rate"]').val((rate).toFixed(2));
        $('input[name="remoney"]').val((money*rate).toFixed(2));
        $('input[name="reintegra"]').val((money*gift/100)*(rate).toFixed(2));  
    });

    form.on('submit(submit)', function (data) {
          $('#submit').attr("disabled",true);
          $('#submit').addClass('layui-btn-disabled');
          $.post('#',data.field,function(res){
              if(res.code == 200){
                  layer.msg(res.msg);
                  setTimeout(() => {
                      // window.parent.location.reload();
                      window.parent.location.href='assets?aid=<!--{$datainfo.aid}-->&action=recharge'
                      xadmin.close();
                  }, 1000);
              }else{
                 layer.msg(res.msg);
              }
          })
        return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。
    });
    //重置按钮，可以提交失败的时候再次提交
    $('#reset').click(function(){
        $('#submit').removeAttr("disabled");
        $('#submit').removeClass('layui-btn-disabled');
    });

    var uploadInst = upload.render({ 
        elem: '#upload', //绑定元素 
        url: '/finance/common/uploadimg/?folder=user', //上传接口 
        done: function(res){ 
            //上传完毕回调 
            console.log(res);
            $('#demo').attr('src', res.data.src); 
            $('#file_url').attr('value', res.data.src);
            $('#picdemo').show(); 
        }, 
        error: function(){ 
           //请求异常回调 
        } 
    }); 
  });
  </script>
</body>
</html>

